import React, { Component } from 'react';

class View extends Component{
    constructor(props){
        super(props);
        this.state = {
            isGoing: true,
            chck:[
                  {checked:false,title:'选择一'},
                  {checked:false,title:'选择二'},
                  {checked:false,title:'选择三'},
              ]
        };
    }
    // 单个input
    handleInputChange(e) {
        const target = e.target;
        const name = target.name;
        this.setState({
            [name]:e.target.checked
        });
    }
    _handleInputChange(e,key) {
        // let target = e.target;
        // let name = target.name;
        const chck = this.state.chck;
        chck[key].checked = !chck[key].checked;
        this.setState({
            chck:chck
        });
    }
    render(){
        return(
            <div className="checkbox">
            <input
                name="isGoing"
                type="checkbox"
                checked={this.state.isGoing}
                onChange={(e)=>this.handleInputChange(e)} />
                <br/>
                {
                    this.state.chck.map((val,key)=>(
                        <label  key={key}>{val.title}<input
                            type="checkbox"
                            checked={val.checked}
                            onChange={(e)=>this._handleInputChange(e,key)} />
                        </label>
                    ))}
            </div>


        )
    }
}

export default View;
